/**
 * @author Feri
*/ 
package com.gdsdxy.dao;
import com.gdsdxy.domain.Cart;
import com.gdsdxy.domain.CartDetail;
import com.gdsdxy.domain.Goods;
import com.gdsdxy.domain.User;
import org.apache.ibatis.annotations.*;

import java.util.List;
public interface UserDao {
	//新增
	@Insert("insert into t_user(role ,username,password,email,gender,createtime ,flag ,activatecode) values(1,#{username},#{password},#{email},#{gender},now(),1,#{activatecode})")
	int insert(User user);
	//插入收藏行
	@Insert("insert into t_collect(uname,cgid) values(#{username},';')")
	int insertCollect(User user);
	//登录 用户名或密码都可以使用
	@Select("select * from t_user where flag=2 and (username=#{name} or email=#{email})")
	@ResultType(User.class)
	User select(String name);
	//检查用户名是否存在
	@Select("select count(*) from t_user where username=#{username}")
	int checkName(String name);
	//检查邮箱是否存在
	@Select("select count(*) from t_user where email=#{email}")
	int checkEmail(String email);
	//检查密码是否存在正确
	@Select("select count(*) from t_user where password=#{password} and username=#{username}")
	int chakePassword(@Param("password") String password,@Param("username") String username );
	//查询全部
	@Select("select * from t_user where flag=2")
	@ResultType(User.class)
	List<User> selectAll();
	//激活
	@Update("update t_user set flag=2 where email=#{email} and activatecode=#{code}")
	int updateAcode(@Param("email") String email, @Param("code") String code);
	//删除用户
	@Delete("delete from t_user where id=#{id} ")
	int deleteByid(int id);
	//根据用户名和性别搜索用户
	@Select("select * from t_user where username like CONCAT('%',#{username},'%')  and gender=#{gender}")
	@ResultType(User.class)
	List<User> selectsearch(@Param("username") String username, @Param("gender") String gender);

	//根据用户名搜索用户
	@Select("select * from t_user where username like CONCAT('%',#{username},'%')")
	@ResultType(User.class)
	List<User> usersearchname(@Param("username") String username);

	//修改个人信息
	@Update("update t_user set username=#{username},password=#{password},email=#{email},gender=#{gender} where id=#{id}")
	public int updateUserinfo(User user);
}